<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Auth extends CI_Controller {
	
	public function __construct() {
		parent::__construct();
		$this->load->model('model_spc');
		$this->load->model('model_auth');
		}
		
	public function index($param='') {
		$this->model_auth->_must_not_logged_in();
		$this->load->view('header', 
			array('title'=> 'ITB Programming Contest 2011 - Login'));
		$this->load->view('form_login',array('param'=>$param));
		$this->load->view('footer');
	}
	
	public function logout() {
		$this->model_auth->_logout();
		redirect('auth/','location');
	}
	
	public function error() {
		//echo $this->input->post('username').'<br/>'.$this->input->post('password');
		$this->model_auth->_must_not_logged_in();
		
		if ($this->input->post()==NULL) {
			redirect('auth/','location');
			}
		
		$result= $this->model_auth->_login($this->input->post());
	
		if (!$result) {
			$this->index('error');
		} else
			redirect($this->model_auth->_get_usertype(),'location');
		// $this->load->view('redirect',$result);
	}
	
	// public function create_admin() {
		// $this->tank_auth->create_user('admin', 'sbycrosz@gmail.com', 'itbpckulparah','admin','9001', FALSE);
	// }
		
	}
	